<template>
<div>

	<el-table
      :data="ab"
      border
      show-summary
      v-loading="loading"
      style="width: 100%">
      	<el-table-column
        	prop="company_code"
        	label="机构编号"
        	width="100">
      	</el-table-column>
      	<el-table-column
        	prop="company_name"
        	label="机构名称"
        	width="180">
      	</el-table-column>
      	<el-table-column
	        prop="total"
	        sortable
	        label="未使用订单金额"
	        width="180">
      	</el-table-column>

      	<el-table-column
	    	fixed="right"
	    	label="操作"
	      >
	      <template slot-scope="scope">
	        <el-button @click="handleClick(scope.row)" type="text" size="small">
	        详情</el-button>
	        <br>
	      </template>
	    </el-table-column>

      
    </el-table>

</div>		
</template>

<script>

import { mapGetters } from 'vuex'

export default {
	name: 'nousedorderlist',
		data () {
		return {
			loading : true,
		 //  	noUsedOrderList : [
			//     {
			//       "company_code": "LW0011",
			//       "title": "11.10测试优惠券",
			//       "price": 3.20,
			//       "company_name": "居游测试微店",
			//       "create_time": "2017-11-14 10:25:31",
			//       "code": "WD1510626331343"
			//     },
			//     {
			//       "company_code": "LW0021",
			//       "title": "11.10测试优惠券",
			//       "price": 3.20,
			//       "company_name": "居游测试微店",
			//       "create_time": "2017-11-14 09:29:55",
			//       "code": "WD1510622994079"
			//     },
			//     {
			//       "company_code": "LW0001",
			//       "title": "11.10测试优惠券",
			//       "price": 3.20,
			//       "company_name": "居游测试微店",
			//       "create_time": "2017-11-14 10:36:31",
			//       "code": "WD1510626991135"
			//     },
			//     {
			//       "company_code": "LW0001",
			//       "title": "11.10测试优惠券",
			//       "price": 3.20,
			//       "company_name": "居游测试微店",
			//       "create_time": "2017-11-14 09:47:13",
			//       "code": "WD1510624033902"
			//     },
			//     {
			//       "company_code": "LW0021",
			//       "title": "我问问问问1",
			//       "price": 0.20,
			//       "company_name": "居游测试微店",
			//       "create_time": "2017-10-19 10:17:48",
			//       "code": "WD1508379468313"
			//     },
			//     {
			//       "company_code": "LW0011",
			//       "title": "我问问问问1",
			//       "price": 0.20,
			//       "company_name": "居游测试微店",
			//       "create_time": "2017-10-19 10:17:48",
			//       "code": "WD1508379468313"
			//     }
			// ]
		}
	},

	props: {

	},

	components: {
		
	},

	computed : {
		...mapGetters([
			'noUsedOrderList',
		]),


		ab () {
			console.log('ab');

			if(this.noUsedOrderList.length > 0) {
				this.loading = false;
			}

			var obj = {};
			for(var i = 0, j = this.noUsedOrderList.length; i < j; i++){
				var tmp = this.noUsedOrderList[i];
				if(obj[tmp.company_code] == undefined){
					obj[tmp.company_code] = []
				}
				obj[tmp.company_code].push(tmp);
			}
			var arr = [];
			for (var key in obj) {
				console.log(key);
			    var o = {
			    	'company_code' : key,
			    	'total' : 0,
			    	'list' : obj[key],
			    };

			    for(var m = 0, n = obj[key].length; m < n; m++){
			    	var t = obj[key][m];
			    	if(o['company_name'] == undefined) {
			    		o['company_name'] = t.company_name;
			    	}
			    	o.total += parseFloat(t.price);
			    }

			    o.total = Math.round(o.total * 100) / 100;
			    arr.push(o);
			}

			console.log('arr');
			console.log(arr);

			return arr;
		}
	},

	methods : {
		
	},

	watch : {
	    
	},

	mounted () {
		this.$store.dispatch('noUsedOrderList');
	},

}
</script>

<style scoped>

</style>
